package com.next.androidintentlibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.app.Context;

public class EventIntents {

    private Context context;
    private Intent intent;

    private EventIntents(Context context)
    {
        this.context = context;
    }

    public static EventIntents from(Context context)
    {
        return new EventIntents(context);
    }

    public EventIntents createEvent(String title, String description)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.EDIT");
        intent.setType("vnd.android.cursor.item/event");
        intent.setParam("title", title);
        intent.setParam("description", description);
        return this;
    }

    public EventIntents createEvent(String title, String description, String location, long begin, long end, int color, boolean allDay)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.INSERT");
       // intent.setData(CalendarContract.Events.CONTENT_URI);
        intent.setParam( "title", title);
        intent.setParam("description", description);
        intent.setParam("eventLocation", location);
        intent.setParam("eventColor", color);
        // TODO: intent.putExtra(CalendarContract.Events.EVENT_TIMEZONE, timeZone);
        intent.setParam("beginTime", begin);
        intent.setParam("endTime", end);
        intent.setParam("allDay", allDay);
        return this;
    }

    public Intent build()
    {
        return intent;
    }

    private void startAbility(Intent intent)
    {
        if (!(context instanceof Ability))
        {
            intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        }
        context.startAbility(intent,0);
    }

    public void show()
    {
        startAbility(build());
    }
}
